package com.purchase.ml.resource.sys;

import com.purchase.ml.annotations.OperLog;
import com.purchase.ml.bean.base.ApiRestResult;
import com.purchase.ml.bean.req.sys.SysUserRoleNewDto;
import com.purchase.ml.bean.req.sys.SysUserRoleQueryDto;
import com.purchase.ml.resource.BaseResource;
import com.purchase.ml.service.sys.ISysRoleUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
* <p>
    * 用户角色表 前端控制器
    * </p>
*
* @author kyyang
* Created 2021-01-20
*/

@Api(tags = "用户角色")
@RestController
@RequestMapping("/user_role")
public class SysUserRoleResource extends BaseResource {

     @Autowired
     private ISysRoleUserService iSysRoleUserService;


    @RequestMapping(method = RequestMethod.POST, path = "/query")
    @ApiOperation("用户角色查询")
    public ApiRestResult sysUserRoleQuery(@Valid @RequestBody SysUserRoleQueryDto sysUserRoleQueryDto) {
        return ApiRestResult.ok(iSysRoleUserService.sysUserRole(sysUserRoleQueryDto));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/new")
    @OperLog(operDesc = "用户角色新建", operModul = "user_role", operType = "new")
    @ApiOperation("用户角色新建")
    public ApiRestResult sysUserRoleNew(@Valid @RequestBody SysUserRoleNewDto sysUserRoleNewDto ) {
        iSysRoleUserService.sysUserRoleNew(sysUserRoleNewDto);
        return ApiRestResult.ok();
    }


    @RequestMapping(method = RequestMethod.DELETE, path = "/del")
    @OperLog(operDesc = "角色删除", operModul = "user_role", operType = "del")
    @ApiOperation("角色删除")
    public ApiRestResult sysRoleDel(@Valid @RequestBody SysUserRoleNewDto sysUserRoleNewDto ) {
        iSysRoleUserService.sysUserRoleDel(sysUserRoleNewDto);
        return ApiRestResult.ok();
    }
}
